<template>
	<MyPage title="历史报价单" :isback="true">
		<view slot="gBody">
			<view class="my-content">

				<view @click="on_views(item)" v-for="(item,index) in list" :key="index"
		  		@longtap="onLongPress(item,index)"
					style="padding: 10px 0px;border-bottom: solid 2rpx #F5F5F5;">
					<text>{{item.title}}</text>
					<view class="">
						<text style="color: #D3D3D3;font-size: 13px;">{{item.time|timeStamp}}</text>
					</view>
				</view>

				<view v-if="list.length==0" class=""
					style="width: 100%;height: 300px;display: flex;justify-content: center;align-items: center;">
					<text style="color: #C0C0C0;">暂无历史报价单</text>
				</view>
			</view>
			<view class="" style="position: fixed;bottom: 100px;right: 40px;">
				<view @click="set_del" class="u-flex" 
				style="width: 90rpx;height: 90rpx;background-color: #D3D3D3;border-radius: 96rpx;color: #fff;
				justify-content: center;">
				 
					<text>清空</text>
				</view>
			</view>
		</view>
	</MyPage>
</template>

<script>
	import mixin from "@/libs/mixin.js";
	import {
		getQuotationloglist,
		getquotationlogdel,
		getquotationlogdels
	} from '@/api/index.js'
	import {
		logout
	} from '@/api/my.js'
	export default {
		mixins: [mixin],
		data() {
			return {
				list: []
			}
		},
		onLoad() {
			this.page = 1;
			this.init();
		},
		filters: {
			timeStamp: function(num) {
				num = num * 1000;
				let date = new Date(num);

				let y = date.getFullYear();

				let MM = date.getMonth() + 1;

				MM = MM < 10 ? ('0' + MM) : MM; //月补0

				let d = date.getDate();

				d = d < 10 ? ('0' + d) : d; //天补0

				let h = date.getHours();

				h = h < 10 ? ('0' + h) : h; //小时补0

				let m = date.getMinutes();

				m = m < 10 ? ('0' + m) : m; //分钟补0

				let s = date.getSeconds();

				s = s < 10 ? ('0' + s) : s; //秒补0

				return y + '-' + MM + '-' + d + ' ' + h + ':' + m + ':' + s;

			}
		},
		methods: {
			set_del(){
				var that = this;
				uni.showModal({ 
					title: '提示',
					content: '确认要清空吗？',
					success: function(res) {
						if (res.confirm) {
							that.is_dels();
						}
					}
				});
			},
			is_dels() {
				var that = this;
				getquotationlogdels({
					token: this.$store.state.app.token,
				 
				}).then(res => {
			
					if (res.list.err == 1) {
						return
					}
					that.list = [];
				}).catch(err => {
			
				});
			},
			// 长按删除
			onLongPress(e, index) {
				var that = this;
				uni.showModal({ 
					title: '提示',
					content: '是否删除此记录',
					success: function(res) {
						if (res.confirm) {
							that.is_del(e.id, index);
						}
					}
				});
			},
			is_del(id, index) {
				var that = this;
				getquotationlogdel({
					token: this.$store.state.app.token,
					z_id: id,
				}).then(res => {
			
					if (res.list.err == 1) {
						return
					}
					that.list = that.list.filter(t => t.id != id);
				}).catch(err => {
			
				});
			},
			on_views(item) {

				uni.navigateTo({
					url: '/pages/compute/content?cycle=' + item.shijian + '&ids=' + item.ids + '&cityKey=' + item
						.cityKey +
						'&log_id=' + item.id+'&lishi_lod_id=' + 1
				})

			},
			init() {
				getQuotationloglist({
					token: this.$store.state.app.token,
					page: this.page,
				}).then(res => { 
					if (this.page == 1) {
						this.list = res.list;
					} else {
						if (res.list.length > 0) {
							for (var i = 0; i < res.list.length; i++) {
								this.list.push(res.list[i]);
							}
						} else {
							this.jiazai = "没有数据了";
						}
					}

				}).catch(err => {

				});


			},
		},
		onReachBottom() {
			this.jiazai = "加载中...";
			this.page = this.page + 1;
			this.init();
		},
	}
</script>

<style lang="scss" scoped>
	.list-group {
		/deep/ .u-border-top:after {
			border-top: none;
		}

		/deep/ .u-cell {
			padding-left: 0;
			padding-right: 0;

			.u-cell_title {
				font-size: 32rpx;
				color: #333;
			}
		}
	}

	.btn {
		position: fixed;
		left: 5%;
		bottom: 50rpx;
		width: 90%;
		color: #dd1010 !important;
		border-color: #B00E0E !important;
	}
</style>